package com.hl.qzzpbackend.controller;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.hl.qzzpbackend.annotation.AuthCheck;
import com.hl.qzzpbackend.common.BaseResponse;
import com.hl.qzzpbackend.common.DeleteRequest;
import com.hl.qzzpbackend.common.ResultUtils;
import com.hl.qzzpbackend.model.dto.job.JobAddRequest;
import com.hl.qzzpbackend.model.dto.job.JobCheckRequest;
import com.hl.qzzpbackend.model.dto.job.JobQueryRequest;
import com.hl.qzzpbackend.model.dto.job.JobUpdateRequest;
import com.hl.qzzpbackend.model.enums.UserRoleEnum;
import com.hl.qzzpbackend.model.vo.JobVO;
import com.hl.qzzpbackend.service.JobService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;


/**
 * 职位信息接口
 *
 * @author helong
 */
@Slf4j
@Api(tags = "职位信息接口")
@RestController
@RequestMapping("/job")
public class JobController {

    @Resource
    private JobService jobService;

    // 新增职位信息
    @ApiOperation(value = "新增职位信息")
    @RequestMapping(value = "/add", method = RequestMethod.POST)
    public BaseResponse<Boolean> jobAdd(@Valid @RequestBody JobAddRequest jobAddRequest) {
        if(log.isInfoEnabled()){
            log.info("新增职位 {}", jobAddRequest);
        }
        boolean result = jobService.jobAdd(jobAddRequest);
        return ResultUtils.success(result);
    }


    // 更新职位信息
    @ApiOperation(value = "更新职位信息")
    @RequestMapping(value = "/update", method = RequestMethod.POST)
    public BaseResponse<Boolean> jobUpdate(@Valid @RequestBody JobUpdateRequest jobUpdateRequest) {
        if(log.isInfoEnabled()){
            log.info("更新职位信息 {}", jobUpdateRequest);
        }
        boolean result = jobService.jobUpdate(jobUpdateRequest);
        return ResultUtils.success(result);
    }

    // 删除职位信息
    @ApiOperation(value = "删除职位信息")
    @RequestMapping(value = "/delete", method = RequestMethod.POST)
    public BaseResponse<Boolean> jobDelete(@Valid @RequestBody DeleteRequest deleteRequest) {
        if(log.isInfoEnabled()){
            log.info("删除职位信息 {}", deleteRequest);
        }
        boolean result = jobService.jobDelete(deleteRequest);
        return ResultUtils.success(result);
    }

    // 获取职位信息详情
    @ApiOperation(value = "获取职位信息详情")
    @RequestMapping(value = "/detail/{id}", method = RequestMethod.GET)
    public BaseResponse<JobVO> jobDetail(@PathVariable("id") Long jobId) {
        if(log.isInfoEnabled()){
            log.info("获取职位信息详情 jobId:{}", jobId);
        }
        JobVO jobVO = jobService.jobDetail(jobId);
        return ResultUtils.success(jobVO);
    }

    // 职位分页
    @ApiOperation(value = "职位分页")
    @RequestMapping(value = "/pageByCondition", method = RequestMethod.POST)
    public BaseResponse<Page<JobVO>> jobPageById(@RequestBody JobQueryRequest jobQueryRequest) {
        if(log.isInfoEnabled()){
            log.info("本公司职位分页 :{}", jobQueryRequest);
        }
        Page<JobVO> page = jobService.jobPageByCondition(jobQueryRequest);
        return ResultUtils.success(page);
    }

    // 审核职位
    @AuthCheck(mustRole = {UserRoleEnum.ADMIN,UserRoleEnum.SUPER_ADMIN})
    @ApiOperation(value = "审核职位")
    @RequestMapping(value = "/jobCheck", method = RequestMethod.POST)
    public BaseResponse<Boolean> jobCheck(@Valid @RequestBody JobCheckRequest jobCheckRequest) {
        if(log.isInfoEnabled()){
            log.info("审核职位 :{}", jobCheckRequest);
        }
        boolean result  = jobService.jobCheck(jobCheckRequest);
        return ResultUtils.success(result);
    }









}
